package day08;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    public static void main(String[] args) {

        List<Book> collection1 = new ArrayList<>();
        collection1.add(new Book(1, 20.0, "Fiction", "Author A"));
        collection1.add(new Book(2, 30.0, "Non-Fiction", "Author B"));
        collection1.add(new Book(3, 25.0, "Fantasy", "Author C"));
        collection1.add(new Book(4, 35.0, "Mystery", "Author D"));


        List<Book> collection2 = new ArrayList<>();
        collection2.add(new Book(2, 30.0, "Non-Fiction", "Author B"));
        collection2.add(new Book(5, 40.0, "Science", "Author E"));


        int duplicates = 0;
        for (Book book : collection1) {
            if (collection2.contains(book)) {
                duplicates++;
            }
        }
        System.out.println("重复的数据个数: " + duplicates);


        Iterator<Book> iterator = collection1.iterator();
        while (iterator.hasNext()) {
            Book book = iterator.next();
            System.out.println(book);
        }


        for (Book book : collection2) {
            System.out.println(book);
        }
    }
}

